package com.wh.hotel.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wh.common.annotation.ResultLog;
import com.wh.common.enums.MethodTypeEnum;
import com.wh.hotel.mapper.HotelRoomTypeGoodsMapper;
import com.wh.hotel.model.HotelRoomTypeGoods;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wenhao
 */
@Slf4j
@Component
public class HotelRoomTypeGoodsDao {

    @Resource
    private HotelRoomTypeGoodsMapper hotelRoomTypeGoodsMapper;


    @ResultLog(name = "HotelRoomTypeGoodsDao.insertBatch", methodType = MethodTypeEnum.DB)
    public boolean insertBatch(List<HotelRoomTypeGoods> goodsList) {
        if (CollectionUtils.isEmpty(goodsList)) {
            return true;
        }
        return hotelRoomTypeGoodsMapper.insertBatch(goodsList) == CollectionUtils.size(goodsList);
    }

    @ResultLog(name = "HotelRoomTypeGoodsDao.selectByRoomTypeId", methodType = MethodTypeEnum.DB, printResult = false)
    public List<HotelRoomTypeGoods> selectByRoomTypeId(Long roomTypeId) {
        LambdaQueryWrapper<HotelRoomTypeGoods> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HotelRoomTypeGoods::getRoomTypeId, roomTypeId);
        return hotelRoomTypeGoodsMapper.selectList(queryWrapper);
    }

    @ResultLog(name = "HotelRoomTypeGoodsDao.deleteBatchByIdList", methodType = MethodTypeEnum.DB)
    public int deleteBatchByIdList(List<Long> goodsIdList) {
        if (CollectionUtils.isEmpty(goodsIdList)) {
            return 0;
        }
        return hotelRoomTypeGoodsMapper.deleteBatchIds(goodsIdList);
    }
}
